<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class panel extends CI_Controller {

	public function __construct()
    {
        parent::__construct();
        $all_session = $this->session->all_userdata();

    
        if($all_session['login'][0]['mem_type'] != 2 && $all_session['login'][0]['mem_type'] != 1)
        {
        	redirect('authen');
        } 

    }

	public function index()
	{
		$data['service'] = $this->panel_model->get_web_service();

		$data['setting'] = $this->psetting_model->index();
		$data['count'] = count($data['setting']);

		$connection = $data['setting'];
		$data['connection'] = $this->connection($connection);

		$sum_vdofile = $this->psetting_model->sum_vdofile();
		$bytes = $sum_vdofile[0]['vdo_size'];
		$this->load->library('calculate_byte');
		$data['sum_vdofile'] = $this->calculate_byte->index($bytes);

		//////////////////////////////////////////////
		//////////////// get top view ////////////////
		//////////////////////////////////////////////
		$data['top_view'] = $this->panel_model->get_top_view();

		//////////////////////////////////////////////
		//////////////// get top like ////////////////
		//////////////////////////////////////////////
		$data['top_like'] = $this->panel_model->like();

		//////////////////////////////////////////////
		//////////////// get top dislike /////////////
		//////////////////////////////////////////////
		$data['top_dislike'] = $this->panel_model->dislike();



		
		$this->load->view('panel',$data);
	}

	public function connection($connection) 
	{ 
		$online = 0;
		$offline = 0;

		for($i=0;$i<count(@$connection);$i++)
		{
			//////////////////////////
			//// test connectjion ////
			//////////////////////////
		    $conn = @fsockopen($connection[$i]['server_ip'], 80, $errno, $errstr, 1); 
		    if ($conn)
		    { 
		        $status[$i] = "Connected"; 
		        $online = $online + 1; 
		        fclose($conn);
		    }else{
		        $status[$i] = "Not connected";
		        $offline = $offline + 1;
		    }
		  	

		}// end loop
		$status['online'] = $online;
		$status['offline'] = $offline;
		return @$status;
	}
}